package game.graphics.away3d
{
	import away3d.core.managers.*;
	import away3d.core.render.*;
	import away3d.events.*;
	import engine.asset.*;
	import engine.core.*;
	import engine.graphics.*;
	import engine.graphics.away3d.*;
	import engine.graphics.lighting.*;
	import engine.graphics.postfx.*;
	import engine.graphics.resources.*;
	import engine.graphics.shader.*;
	import engine.graphics.vfx.*;
	import engine.loaders.*;
	import engine.math.*;
	import engine.profile.*;
	import flash.display.*;
	import flash.display3D.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.utils.*;
	import game.asset.*;
	import game.graphics.*;
	import game.graphics.lighting.*;
	import game.graphics.shader.*;

	public class RxRenderer extends RendererBase
	{
		private var m_camera:RxCamera3D;
		private var m_shaderFamilyManager:RxShaderFamilyManager;
		private var m_uberPostFX:RxUberPostFX;
		private var m_lightFilter:RxLightFilter;
		private var m_fxManager:RxWorldFXManager;
		private var m_debugRender:RxDebugRender;
		private var m_sunLightWorldSpace:RxDirectionalLight;
		private var m_sunLightViewSpace:RxDirectionalLight;
		private var m_shaderFamilyCharacter:RxShaderFamilyCharacter;
		private var m_shaderFamilyEnvironment:RxShaderFamilyEnvironment;
		private var m_shaderFamilyWorldObject:RxShaderFamilyWorldObject;
		private var m_shaderFamilyWater:RxShaderFamilyWater;
		private var m_shaderFamilyMeshFX:RxShaderFamilyMeshFX;
		private var m_shaderFamilySpriteFX:RxShaderFamilySpriteFX;
		private var m_shaderFamilyParticle:RxShaderFamilyParticle;
		private var m_shaderFamilyPointLight:RxShaderFamilyPointLight;
		private var m_shaderParameters:RxUVProjectShaderParameters;
		private var m_gigaTexture:RxGigaTextureInfo;
		private var m_virtualTexture:RxVirtualTexture;
		private var m_uvViewMatrix:RxMatrix4x4;
		private var m_uvProjMatrix:RxMatrix4x4;
		private var m_uvViewProjMatrix:RxMatrix4x4;
		private var m_minViewAlignedPosition:RxVector4;
		private var m_maxViewAlignedPosition:RxVector4;
		private var m_sceneAsset:RxAssetScene;
		private var m_environmentMesh:RxEnvironmentMesh;
		private var m_gbuffer:RxGBuffer;
		private var m_maxBackbufferWidth:uint;
		private var m_maxBackbufferHeight:uint;
		private var m_noiseTexture:RxGPUTexture2D;
		private var m_nullTexture:RxGPUTexture2D;
		private var m_environmentCubeTexture:RxCubeTexture;
		private var m_debugRenderPass:uint;
		private var m_viewports:Vector.<RxViewport>;
		private var m_worker:RxTimerWorker;
		private var m_dualProfiler:RxDualProfiler;
		private var m_lightingMode:uint;
		private var m_antiAlias:uint;
		private var m_graphicsQuality:int;
		private var m_displayBBoxes:uint;
		private var m_softwareMode:Boolean;
		private var m_disableAll:Boolean;
		private var m_disableUpdates:Boolean;
		private var m_disableVFX:Boolean;
		private var m_disablePostFX:Boolean;
		private var m_gpuPerfScore:Number;
		private var m_gpuPerfTime:Number;
		private var m_cpuPerfScore:Number;
		private var m_cpuPerfTime:Number;
		private var m_lostDevice:Boolean;
		private var m_virtualTextureDebugRect:Rectangle = null;
		public static const VIEWPORT_INVENTORY_CHARACTER:uint = 0;
		public static const VIEWPORT_INSPECTOR:uint = 1;
		public static const NUM_VIEWPORTS:uint = 2;
		public static const RENDER_PASS_DEFERRED_ALBEDO:uint = 0;
		public static const RENDER_PASS_DEFERRED_DEPTH:uint = 1;
		public static const RENDER_PASS_DEFERRED_NORMALS:uint = 2;
		public static const RENDER_PASS_FORWARD_LIT:uint = 3;
		public static const LIGHTING_MODE_OFF:uint = 0;
		public static const LIGHTING_MODE_BASIC:uint = 1;
		public static const LIGHTING_MODE_DEFERRED:uint = 2;
		public static const GRAPHICS_QUALITY_SOFTWARE:int = -1;
		public static const GRAPHICS_QUALITY_LOW:int = 0;
		public static const GRAPHICS_QUALITY_MEDIUM:int = 1;
		public static const GRAPHICS_QUALITY_HIGH:int = 2;
		public static const GRAPHICS_QUALITY_ULTRA:int = 3;
		public static const ANTI_ALIAS_OFF:uint = 0;
		public static const ANTI_ALIAS_2x:uint = 2;
		public static const ANTI_ALIAS_4x:uint = 4;
		public static const ANTI_ALIAS_16x:uint = 16;
		public static var s_instance:RxRenderer = null;
		
		public function RxRenderer(camera:RxCamera3D, worker:RxTimerWorker, frameDualProfiler:RxDualProfiler)
		{
			s_instance = this;
			this.m_camera = camera;
			this.m_worker = worker;
			this.m_shaderFamilyManager = new RxShaderFamilyManager();
			this.m_uberPostFX = null;
			this.m_lightFilter = null;
			this.m_fxManager = null;
			this.m_debugRender = null;
			this.m_sunLightWorldSpace = new RxDirectionalLight();
			this.m_sunLightViewSpace = new RxDirectionalLight();
			this.m_shaderFamilyCharacter = null;
			this.m_shaderFamilyEnvironment = null;
			this.m_shaderFamilyWorldObject = null;
			this.m_shaderFamilyWater = null;
			this.m_shaderFamilyMeshFX = null;
			this.m_shaderFamilySpriteFX = null;
			this.m_shaderFamilyParticle = null;
			this.m_shaderFamilyPointLight = null;
			this.m_shaderParameters = null;
			this.m_gigaTexture = null;
			this.m_virtualTexture = null;
			this.m_uvViewMatrix = new RxMatrix4x4();
			this.m_uvProjMatrix = new RxMatrix4x4();
			this.m_uvViewProjMatrix = new RxMatrix4x4();
			this.m_minViewAlignedPosition = new RxVector4();
			this.m_maxViewAlignedPosition = new RxVector4();
			this.m_sceneAsset = null;
			this.m_environmentMesh = null;
			this.m_gbuffer = null;
			this.m_maxBackbufferWidth = 2048;
			this.m_maxBackbufferHeight = 2048;
			this.m_noiseTexture = null;
			this.m_nullTexture = null;
			this.m_environmentCubeTexture = null;
			this.m_debugRenderPass = RENDER_PASS_DEFERRED_ALBEDO;
			this.m_viewports = new Vector.<RxViewport>(NUM_VIEWPORTS, true);
			this.m_dualProfiler = frameDualProfiler;
			this.m_lightingMode = LIGHTING_MODE_DEFERRED;
			this.m_graphicsQuality = GRAPHICS_QUALITY_HIGH;
			this.m_antiAlias = ANTI_ALIAS_4x;
			this.m_softwareMode = false;
			this.m_displayBBoxes = 0;
			this.m_disableAll = false;
			this.m_disableUpdates = false;
			this.m_disableVFX = false;
			this.m_disablePostFX = false;
			this.m_gpuPerfScore = 0;
			this.m_gpuPerfTime = 0;
			this.m_cpuPerfScore = 0;
			this.m_cpuPerfTime = 0;
			this.m_lostDevice = false;
		}
		
		public function ResizeBackbuffer(width:uint, height:uint) : void
		{
			
		}
		
		public function GetShaderFamilyManager() : RxShaderFamilyManager
		{
			return this.m_shaderFamilyManager;
		}
		
		public function DisplayBBoxes(param1:uint) : void
		{
			this.m_displayBBoxes = param1;
		}
		
		public function DisableAll(param1:Boolean) : void
		{
			this.m_disableAll = param1;
		}
		
		public function DisableUpdates(param1:Boolean) : void
		{
			this.m_disableUpdates = param1;
		}
		
		public function DisablePostFX(param1:Boolean) : void
		{
			this.m_disablePostFX = param1;
		}
		
		public function DisableVFX(param1:Boolean) : void
		{
			this.m_disableVFX = param1;
		}
		
		public function DisableRenderCalls(param1:Boolean) : void
		{
			RxShaderFamilyBase.s_disableRenderCalls = param1;
		}
		
		public function SetGPUPerfScore(param1:Number) : void
		{
			this.m_gpuPerfScore = param1;
		}
		
		public function GetGPUPerfScore() : Number
		{
			return this.m_gpuPerfScore;
		}
		
		public function SetGPUPerfTime(param1:Number) : void
		{
			this.m_gpuPerfTime = param1;
		}
		
		public function GetGPUPerfTime() : Number
		{
			return this.m_gpuPerfTime;
		}
		
		public function SetCPUPerfScore(param1:Number) : void
		{
			this.m_cpuPerfScore = param1;
		}
		
		public function GetCPUPerfScore() : Number
		{
			return this.m_cpuPerfScore;
		}
		
		public function SetCPUPerfTime(param1:Number) : void
		{
			this.m_cpuPerfTime = param1;
		}
		
		public function GetCPUPerfTime() : Number
		{
			return this.m_cpuPerfTime;
		}
		
		public static function GetInstance() : RxRenderer
		{
			return s_instance;
		}
		
		public function CheckForLostDevice() : Boolean
		{
			var _loc_1:Stage3D = null;
			var _loc_2:Context3D = null;
			if (_context != null)
			{
				_loc_1 = _stage3DProxy.GetStage3D();
				_loc_2 = _loc_1.context3D;
				if (_loc_2 == null)
				{
					_context = null;
					this.m_lostDevice = true;
					RxLog.Info("Device was lost");
				}
			}
			return this.m_lostDevice;
		}
		
		public function GetVirtualTexture() : RxVirtualTexture
		{
			return this.m_virtualTexture;
		}
		
		public function LoadGigaTexture() : void
		{
			var _loc_1:RxVector4 = null;
			var _loc_2:RxVector4 = null;
			var _loc_3:uint = 0;
			var _loc_4:uint = 0;
			if (this.m_gigaTexture != null)
			{
				_loc_1 = this.m_camera.GetPosition();
				_loc_2 = RxVector4.PoolAlloc();
				RxVector4.MulMatrix4x4(_loc_2, _loc_1, this.m_uvViewProjMatrix);
				_loc_3 = _loc_2.x * this.m_gigaTexture.GetTotalWidth();
				_loc_4 = _loc_2.y * this.m_gigaTexture.GetTotalHeight();
				this.m_virtualTexture.UpdateCacheGrid(_loc_3, _loc_4);
				RxVector4.PoolFree(_loc_2);
				_loc_2 = null;
			}
			return;
		}
		
		public function GetStage3DProxy() : Stage3DProxy
		{
			return _stage3DProxy;
		}
		
		public function GetGraphicsQuality() : int
		{
			return this.m_graphicsQuality;
		}
		
		public function Update(param1:Number, param2:RxScene) : void
		{
			var _loc_3:RxViewport = null;
			if (this.m_disableAll || this.m_disableUpdates || this.m_lostDevice)
			{
				return;
			}
			param2.Update(param1);
			if (!this.m_disableVFX && this.m_fxManager)
			{
				//this.m_fxManager.Update(param1);
			}
			for each (_loc_3 in this.m_viewports)
			{
				
				if (_loc_3 != null)
				{
					//_loc_3.Update(param1);
				}
			}
		}
		
		public function Clear() : void
		{
			if (_context)
			{
				_context.clear(_backgroundR, _backgroundG, _backgroundB, _backgroundAlpha, 1, 0, 4294967295);
			}
		}
		
		public function RenderScene(param1:RxScene) : void
		{
			/*
			var _loc_6:uint = 0;
			var _loc_7:uint = 0;
			var _loc_10:RxViewport = null;
			var _loc_11:uint = 0;
			var _loc_12:RxRenderTarget = null;
			var _loc_13:RxRenderTarget = null;
			var _loc_14:RxVector4 = null;
			var _loc_15:RxVector4 = null;
			var _loc_16:Number = NaN;
			var _loc_17:Number = NaN;
			var _loc_18:uint = 0;
			if (!_context || !this.m_gbuffer || this.m_disableAll || this.m_lostDevice)
			{
				return;
			}
			var _loc_2:* = param1.GetNumVisibleOpaqueMeshes() + param1.GetNumVisibleTranslucentMeshes();
			this.m_dualProfiler.Start("render (" + _loc_2 + " / " + param1.GetNumMeshes() + ")");
			this.UnbindResources();
			this.StreamGigaTexture();
			var _loc_3:* = this.m_camera.GetViewMatrix();
			var _loc_4:* = this.m_uberPostFX.GetTextureBlitter();
			this.UpdateShaderLighting(this.m_sunLightWorldSpace, _loc_3);
			var _loc_5:* = this.m_gbuffer.GetRenderTarget(RxGBuffer.GBUFFER_ALBEDO);
			this.m_camera.SetViewportRect(_loc_5.GetNormalizedRect());
			this.m_shaderParameters.SetupConstants(this.m_camera);
			this.UnbindResources();
			this.SetDefaultStates();
			this.m_dualProfiler.Start("opaque");
			if (this.m_lightingMode == LIGHTING_MODE_OFF)
			{
				this.RenderOpaqueObjectsToGBuffer(RENDER_PASS_DEFERRED_ALBEDO, this.m_antiAlias, param1);
			}
			else if (this.m_lightingMode == LIGHTING_MODE_BASIC)
			{
				this.RenderOpaqueObjectsToGBuffer(RENDER_PASS_DEFERRED_ALBEDO, this.m_antiAlias, param1);
				this.m_dualProfiler.Start("lighting basic");
				_stage3DProxy.SetDepthTest(false, Stage3DProxy.COMPARE_MODE_LESS_EQUAL);
				_stage3DProxy.SetBlendFactors(Stage3DProxy.BLEND_FACTOR_DESTINATION_COLOR, Stage3DProxy.BLEND_FACTOR_ONE);
				this.m_fxManager.GetPointLightMesh().SetShaderFeatures(RxShaderFamilyPointLight.FEATURE_BASIC);
				this.m_fxManager.RenderLights(RENDER_PASS_DEFERRED_ALBEDO);
				this.m_shaderFamilyPointLight.RenderObjects(_stage3DProxy, this.m_camera);
				this.m_dualProfiler.End();
			}
			else if (this.m_lightingMode == LIGHTING_MODE_DEFERRED)
			{
				this.RenderOpaqueObjectsToGBuffer(RENDER_PASS_DEFERRED_DEPTH, ANTI_ALIAS_OFF, param1);
				this.RenderOpaqueObjectsToGBuffer(RENDER_PASS_DEFERRED_NORMALS, ANTI_ALIAS_OFF, param1);
				this.m_dualProfiler.Start("lighting deferred");
				_loc_12 = this.PrepareGBufferRenderTarget(RxGBuffer.GBUFFER_LIGHT_ACCUM, ANTI_ALIAS_OFF, 0, 0, 0, 0);
				_stage3DProxy.SetDepthTest(false, Stage3DProxy.COMPARE_MODE_LESS_EQUAL);
				_stage3DProxy.SetBlendFactors(Stage3DProxy.BLEND_FACTOR_ONE, Stage3DProxy.BLEND_FACTOR_ONE);
				_stage3DProxy.SetCulling(Stage3DProxy.TRIANGLE_FACE_FRONT);
				this.m_fxManager.GetPointLightMesh().SetShaderFeatures(RxShaderFamilyPointLight.FEATURE_DEFAULT);
				this.m_fxManager.RenderLights(RENDER_PASS_DEFERRED_ALBEDO);
				this.m_shaderFamilyPointLight.RenderObjects(_stage3DProxy, this.m_camera);
				_stage3DProxy.SetCulling(Stage3DProxy.TRIANGLE_FACE_BACK);
				this.m_dualProfiler.End();
				_loc_13 = this.RenderOpaqueObjectsToGBuffer(RENDER_PASS_DEFERRED_ALBEDO, this.m_antiAlias, param1);
				_stage3DProxy.SetBlendFactors(Stage3DProxy.BLEND_FACTOR_DESTINATION_COLOR, Stage3DProxy.BLEND_FACTOR_ONE);
				_stage3DProxy.SetDepthTest(false, Stage3DProxy.COMPARE_MODE_ALWAYS);
				_loc_4.SetDstRect(_loc_12.GetNormalizedRect());
				_loc_4.SetSrcRect(0, _loc_12.GetNormalizedRect());
				_loc_4.SetTexture(0, _loc_12.GetTexture());
				_loc_4.Render(_stage3DProxy);
				this.UnbindResources();
			}
			this.m_dualProfiler.End();
			this.m_dualProfiler.Start("translucent");
			this.m_shaderFamilyManager.ClearRenderableLists();
			_stage3DProxy.SetDepthTest(false, Stage3DProxy.COMPARE_MODE_LESS_EQUAL);
			param1.RenderTranslucentMeshes(_stage3DProxy, RENDER_PASS_FORWARD_LIT);
			if (!this.m_disableVFX)
			{
				_loc_6 = this.m_fxManager.GetNumOpaqueFX() + this.m_fxManager.GetNumTranslucentFX() + this.m_fxManager.GetNumRefractingFX(0);
				_loc_7 = this.m_fxManager.GetNumVisibleOpaqueFX() + this.m_fxManager.GetNumVisibleTranslucentFX() + this.m_fxManager.GetNumVisibleRefractingFX(0);
				if (_loc_7)
				{
					this.m_dualProfiler.Start("vfx (" + _loc_7 + " / " + _loc_6 + ")");
					this.m_fxManager.RenderOpaqueVFX(RENDER_PASS_FORWARD_LIT);
					this.m_fxManager.RenderTranslucentVFX(RENDER_PASS_FORWARD_LIT);
					this.m_fxManager.RenderRefractingVFX(RENDER_PASS_FORWARD_LIT, 0);
					this.m_dualProfiler.End();
				}
			}
			this.m_shaderFamilyManager.RenderObjects(_stage3DProxy, this.m_camera);
			this.m_dualProfiler.End();
			if (this.m_displayBBoxes)
			{
				_stage3DProxy.SetBlendFactors(Stage3DProxy.BLEND_FACTOR_SOURCE_ALPHA, Stage3DProxy.BLEND_FACTOR_ONE);
				_stage3DProxy.SetDepthTest(false, Stage3DProxy.COMPARE_MODE_LESS_EQUAL);
				_stage3DProxy.SetColorMask(Stage3DProxy.COLOR_MASK_RGB);
				_loc_14 = RxVector4.PoolAlloc();
				_loc_15 = RxVector4.PoolAlloc();
				_loc_14.Set(0.2, 0.8, 0.2, 0.25);
				_loc_15.Set(0.8, 0.2, 0.2, 0.25);
				param1.RenderBBoxes(_stage3DProxy, this.m_debugRender, this.m_camera, this.m_displayBBoxes & 1 ? (_loc_14) : (null), this.m_displayBBoxes & 2 ? (_loc_15) : (null));
				_stage3DProxy.SetColorMask(Stage3DProxy.COLOR_MASK_RGBA);
				RxVector4.PoolFree(_loc_15);
				_loc_15 = null;
				RxVector4.PoolFree(_loc_14);
				_loc_14 = null;
			}
			this.SetDefaultStates();
			var _loc_8:* = this.m_gbuffer.GetRenderTarget(this.m_debugRenderPass);
			var _loc_9:RxRenderTarget = null;
			if (!this.m_disablePostFX && this.m_debugRenderPass == RxGBuffer.GBUFFER_ALBEDO)
			{
				this.m_dualProfiler.Start("postfx");
				_loc_9 = this.m_gbuffer.GetRenderTarget(RxGBuffer.GBUFFER_LIGHT_ACCUM);
				stage3DProxy.SetDepthTest(false, Stage3DProxy.COMPARE_MODE_ALWAYS);
				this.m_uberPostFX.Render(_stage3DProxy, _loc_9, _loc_8);
				stage3DProxy.SetDepthTest(true, Stage3DProxy.COMPARE_MODE_LESS_EQUAL);
				_loc_8 = _loc_9;
				this.m_dualProfiler.End();
			}
			_stage3DProxy.SetRenderTarget(null);
			_stage3DProxy.SetScissorRect(0, 0, _stage3DProxy.backBufferWidth, _stage3DProxy.backBufferHeight);
			_loc_4.SetDstRect(null);
			_loc_4.Filter(_stage3DProxy, null, _loc_8);
			if (!this.m_disableVFX)
			{
				_loc_6 = this.m_fxManager.GetNumRefractingFX(1);
				_loc_7 = this.m_fxManager.GetNumVisibleRefractingFX(1);
				if (_loc_7)
				{
					this.UnbindResources();
					this.SetDefaultStates();
					stage3DProxy.SetDepthTest(false, Stage3DProxy.COMPARE_MODE_ALWAYS);
					_loc_16 = Number(_loc_8.GetWidth()) / Number(_loc_8.GetWidthPow2());
					_loc_17 = Number(_loc_8.GetHeight()) / Number(_loc_8.GetHeightPow2());
					this.m_shaderFamilyMeshFX.SetRefractionWidthScale(_loc_16);
					this.m_shaderFamilyMeshFX.SetRefractionHeightScale(_loc_17);
					this.m_shaderFamilySpriteFX.SetRefractionWidthScale(_loc_16);
					this.m_shaderFamilySpriteFX.SetRefractionHeightScale(_loc_17);
					this.m_shaderFamilyParticle.SetRefractionWidthScale(_loc_16);
					this.m_shaderFamilyParticle.SetRefractionHeightScale(_loc_17);
					this.m_camera.SetViewportRect(null);
					this.m_shaderParameters.SetupConstants(this.m_camera);
					this.m_shaderParameters.SetColorTexture(_loc_8.GetTexture());
					this.m_shaderParameters.SetDepthTexture(this.m_virtualTexture.GetMappedDepthTexture());
					this.m_shaderFamilyMeshFX.SetRefractionLayer(1);
					this.m_shaderFamilySpriteFX.SetRefractionLayer(1);
					this.m_shaderFamilyParticle.SetRefractionLayer(1);
					this.m_shaderFamilyManager.ClearRenderableLists();
					this.m_dualProfiler.Start("vfx refr (" + this.m_fxManager.GetNumVisibleRefractingFX(1) + " / " + this.m_fxManager.GetNumRefractingFX(1) + ")");
					this.m_fxManager.RenderRefractingVFX(RENDER_PASS_FORWARD_LIT, 1);
					this.m_dualProfiler.End();
					this.m_shaderFamilyManager.RenderObjects(_stage3DProxy, this.m_camera);
					this.m_shaderParameters.SetColorTexture(this.m_virtualTexture.GetMappedColorTexture());
					this.m_shaderParameters.SetDepthTexture(this.m_virtualTexture.GetMappedDepthTexture());
					this.m_shaderFamilyMeshFX.SetRefractionLayer(0);
					this.m_shaderFamilySpriteFX.SetRefractionLayer(0);
					this.m_shaderFamilyParticle.SetRefractionLayer(0);
					this.UnbindResources();
					this.SetDefaultStates();
				}
			}
			for each (_loc_10 in this.m_viewports)
			{
				
				if (_loc_10 != null && _loc_10.GetCamera() != null)
				{
					this.UpdateShaderLighting(_loc_10.GetSunLight(), _loc_3);
					this.m_shaderParameters.SetupConstants(_loc_10.GetCamera());
					this.m_shaderFamilyManager.ClearRenderableLists();
					_loc_10.Render(RENDER_PASS_FORWARD_LIT, _stage3DProxy, null);
					this.m_shaderFamilyManager.RenderObjects(stage3DProxy, this.m_camera);
				}
			}
			_loc_11 = RxClientVars.GetInt("debugGigaTexture");
			if (_loc_11)
			{
				_loc_18 = _loc_11 == 1 ? (RxGigaTextureInfo.TEXTURE_TYPE_COLOR) : (RxGigaTextureInfo.TEXTURE_TYPE_DEPTH);
				this.VirtualTextureDebugView(_loc_18);
			}
			this.UnbindResources();
			this.m_dualProfiler.End();
			*/
		}
		
		public function Present() : void
		{
			if (_context)
			{
				_context.present();
			}
		}
		
		public function SetUVProjection(param1:RxVector4, param2:Number, param3:Number, param4:Number, param5:Number, param6:Number, param7:Number, param8:Number) : RxMatrix4x4
		{
			RxCamera3D.CreateOrthoViewProjectionMatrix(this.m_uvViewMatrix, this.m_uvProjMatrix, param1, param2, param3, param4, param5, param6, param7, param8);
			this.m_uvProjMatrix.PostMulScale(0.5, -0.5, 1);
			this.m_uvProjMatrix.PostMulTranslate(0.5, 0.5, 0);
			RxMatrix4x4.Mul4x4(this.m_uvViewProjMatrix, this.m_uvViewMatrix, this.m_uvProjMatrix);
			this.m_shaderParameters.SetProjMatrix(this.m_uvViewProjMatrix);
			return this.m_uvViewProjMatrix;
		}
		
		public function SetGraphicsQuality(param1:int) : void
		{
			/*
			this.m_graphicsQuality = param1;
			switch(this.m_graphicsQuality)
			{
				case GRAPHICS_QUALITY_SOFTWARE:
				{
					this.m_maxBackbufferWidth = 1024;
					this.m_maxBackbufferHeight = 512;
					this.m_antiAlias = ANTI_ALIAS_OFF;
					this.m_lightingMode = LIGHTING_MODE_OFF;
					this.m_disablePostFX = true;
					break;
				}
				case GRAPHICS_QUALITY_LOW:
				{
					this.m_maxBackbufferWidth = 1536;
					this.m_maxBackbufferHeight = 768;
					this.m_antiAlias = ANTI_ALIAS_OFF;
					this.m_lightingMode = LIGHTING_MODE_BASIC;
					this.m_disablePostFX = false;
					this.m_uberPostFX.EnableBlur(false);
					this.m_uberPostFX.SetGaussianFilterQualityOnDownsamples(0);
					this.m_uberPostFX.SetGaussianFilterQualityOnBlurs(0);
					this.m_uberPostFX.SetNumDownsamples(0);
					break;
				}
				case GRAPHICS_QUALITY_MEDIUM:
				{
					this.m_maxBackbufferWidth = 2048;
					this.m_maxBackbufferHeight = 1024;
					this.m_antiAlias = ANTI_ALIAS_OFF;
					this.m_lightingMode = LIGHTING_MODE_BASIC;
					this.m_disablePostFX = false;
					this.m_uberPostFX.EnableBlur(false);
					this.m_uberPostFX.SetGaussianFilterQualityOnDownsamples(0);
					this.m_uberPostFX.SetGaussianFilterQualityOnBlurs(RxUberPostFX.GAUSSIAN_KERNEL_7x7);
					this.m_uberPostFX.SetNumDownsamples(4);
					break;
				}
				case GRAPHICS_QUALITY_HIGH:
				{
					this.m_maxBackbufferWidth = 2048;
					this.m_maxBackbufferHeight = 1024;
					this.m_antiAlias = ANTI_ALIAS_OFF;
					this.m_lightingMode = LIGHTING_MODE_DEFERRED;
					this.m_disablePostFX = false;
					this.m_uberPostFX.EnableBlur(true);
					this.m_uberPostFX.SetGaussianFilterQualityOnDownsamples(RxUberPostFX.GAUSSIAN_KERNEL_7x7);
					this.m_uberPostFX.SetGaussianFilterQualityOnBlurs(0);
					this.m_uberPostFX.SetNumDownsamples(-1);
					break;
				}
				case GRAPHICS_QUALITY_ULTRA:
				{
					this.m_maxBackbufferWidth = 2048;
					this.m_maxBackbufferHeight = 2048;
					this.m_antiAlias = ANTI_ALIAS_OFF;
					this.m_lightingMode = LIGHTING_MODE_DEFERRED;
					this.m_disablePostFX = false;
					this.m_uberPostFX.EnableBlur(true);
					this.m_uberPostFX.SetGaussianFilterQualityOnDownsamples(RxUberPostFX.GAUSSIAN_KERNEL_7x7);
					this.m_uberPostFX.SetGaussianFilterQualityOnBlurs(RxUberPostFX.GAUSSIAN_KERNEL_15x15);
					this.m_uberPostFX.SetNumDownsamples(-1);
					break;
				}
				default:
				{
					break;
				}
			}
			this.ResizeBackbuffer(_stage3DProxy.backBufferWidth, _stage3DProxy.backBufferHeight);
			*/
		}
		
		public function GPUPerfTest() : Number
		{
			/*
			var _loc_7:uint = 0;
			var _loc_11:Number = NaN;
			if (!_context)
			{
				return 0;
			}
			if (this.m_softwareMode)
			{
				return 0;
			}
			this.UnbindResources();
			this.SetDefaultStates();
			_stage3DProxy.SetBlendFactors(Stage3DProxy.BLEND_FACTOR_SOURCE_ALPHA, Stage3DProxy.BLEND_FACTOR_ONE_MINUS_SOURCE_ALPHA);
			_stage3DProxy.SetDepthTest(true, Stage3DProxy.COMPARE_MODE_ALWAYS);
			var _loc_1:* = this.m_uberPostFX.GetTextureBlitter();
			var _loc_2:* = new RxRenderTarget();
			var _loc_3:* = new RxRenderTarget();
			_loc_2.Create(_context, 2048, 2048);
			_loc_3.Create(_context, 2048, 2048);
			_loc_2.BindAsRenderTarget(_stage3DProxy, false, 0);
			_context.clear(0, 0, 0, 0, 1, 0, 4294967295);
			_loc_1.SetDstRect(null);
			_loc_1.SetSrcRect(0, null);
			var _loc_4:* = new BitmapData(1, 1, true, 0);
			_context.drawToBitmapData(_loc_4);
			_loc_3.BindAsRenderTarget(_stage3DProxy, false, 0);
			_context.clear(0, 0, 0, 0, 1, 0, 4294967295);
			_loc_1.SetTexture(0, _loc_2.GetTexture());
			var _loc_5:* = getTimer();
			var _loc_6:uint = 100;
			_loc_1.Render(_stage3DProxy);
			var _loc_8:* = _loc_1.GetIndexBuffer().GetIndexBuffer();
			_loc_7 = 1;
			while (_loc_7 < _loc_6)
			{
				
				_context.drawTriangles(_loc_8, 0, 2);
				_loc_7 = _loc_7 + 1;
			}
			_stage3DProxy.SetRenderTarget(null);
			_stage3DProxy.DisableScissor();
			_context.clear(0, 0, 0, 0, 1, 0, 4294967295);
			_loc_1.SetTexture(0, _loc_3.GetTexture());
			_loc_1.Render(_stage3DProxy);
			_context.drawToBitmapData(_loc_4);
			_context.present();
			var _loc_9:* = getTimer();
			var _loc_10:* = (getTimer() - _loc_5) * 0.001;
			_loc_11 = _loc_6 * _loc_3.GetWidthPow2() * _loc_3.GetHeightPow2();
			_loc_11 = _loc_11 + _stage3DProxy.backBufferWidth * _stage3DProxy.backBufferHeight;
			var _loc_12:* = _loc_11 / _loc_10;
			this.m_gpuPerfScore = _loc_12 * 1e-009;
			this.m_gpuPerfTime = _loc_10;
			this.UnbindResources();
			this.SetDefaultStates();
			_loc_4.dispose();
			_loc_4 = null;
			_loc_2.Delete();
			_loc_2 = null;
			_loc_3.Delete();
			_loc_3 = null;*/
			return this.m_gpuPerfScore;
		}
		
		public function CPUPerfTest() : Number
		{
			var _loc_1:* = new BitmapData(512, 512, true, 0);
			var _loc_2:* = getTimer();
			var _loc_3:uint = 8;
			_loc_1.perlinNoise(_loc_1.width / 16, _loc_1.height / 16, _loc_3, 0, true, true, 15, false);
			var _loc_4:* = getTimer();
			this.m_cpuPerfTime = 0.001 * Number(_loc_4 - _loc_2);
			this.m_cpuPerfScore = _loc_1.width * _loc_1.height * _loc_3 / this.m_cpuPerfTime;
			this.m_cpuPerfScore = this.m_cpuPerfScore * 1e-006;
			_loc_1.dispose();
			_loc_1 = null;
			return this.m_cpuPerfScore;
		}
		
		public function GetUberPostFX() : RxUberPostFX
		{
			return this.m_uberPostFX;
		}
		
		public function GetFXManager() : RxWorldFXManager
		{
			return this.m_fxManager;
		}
		
		public function GetDebugRender() : RxDebugRender
		{
			return this.m_debugRender;
		}
		
		public function GetSunLight() : RxDirectionalLight
		{
			return this.m_sunLightWorldSpace;
		}
		
		public function GetViewport(param1:uint) : RxViewport
		{
			var _loc_2:RxViewport = null;
			if (param1 < NUM_VIEWPORTS)
			{
				_loc_2 = this.m_viewports[param1];
			}
			return _loc_2;
		}
		
		public function GetMinViewAlignedPosition() : RxVector4
		{
			return this.m_minViewAlignedPosition;
		}
		
		public function GetMaxViewAlignedPosition() : RxVector4
		{
			return this.m_maxViewAlignedPosition;
		}
		
		public function SetScene(param1:RxAssetScene) : void
		{
			this.m_sceneAsset = param1;
		}
		
		public function GetScene() : RxAssetScene
		{
			return this.m_sceneAsset;
		}
		
		public function GetEnvironmentMesh() : RxEnvironmentMesh
		{
			return this.m_environmentMesh;
		}
		
		public function GetWorldFXManager() : RxWorldFXManager
		{
			return this.m_fxManager;
		}
		
		public function GetWorker() : RxTimerWorker
		{
			return this.m_worker;
		}
		
		public function IsSoftwareMode() : Boolean
		{
			return m_softwareMode;
		}
		
		public function SetGraphicsQualityAuto() : int
		{
			var _loc_1:int = 0;
			if (this.m_softwareMode)
			{
				_loc_1 = GRAPHICS_QUALITY_SOFTWARE;
			}
			else if (this.m_gpuPerfScore > 10)
			{
				_loc_1 = GRAPHICS_QUALITY_ULTRA;
			}
			else if (this.m_gpuPerfScore > 5)
			{
				_loc_1 = GRAPHICS_QUALITY_HIGH;
			}
			else if (this.m_gpuPerfScore > 0.5)
			{
				_loc_1 = GRAPHICS_QUALITY_MEDIUM;
			}
			else if (this.m_gpuPerfScore > 0)
			{
				_loc_1 = GRAPHICS_QUALITY_LOW;
			}
			else
			{
				_loc_1 = GRAPHICS_QUALITY_MEDIUM;
			}
			this.SetGraphicsQuality(_loc_1);
			return _loc_1;
		}
	}
}